#ifndef CONTROLER_H_
#define CONTROLER_H_

#include <QtCore>
#include <QtGui>
#include <QDebug>
#include "tools.h"
#include "highgui.h"
#include "cxcore.h"
#include "cv.h"

#include "videoprocessor.h"
#include "sqlprocessor.h"

/*! \brief Classe controler \n
  *	Elle permet la gestion des differents modules de traitement, c'est le CONTROLEUR
  *	principal de l'application
  *	@author Alain Simac-Lejeune
  */

class controler
{
public:

	controler();

	// zone 1

	void initialiazeVideoProcessing(QString filename);
	void initializeVideoProcessor();
	void preprocessingFrame();
	void processingFrame();

	void initialiazeVideoDatabase(QString filename);

		int getFormatImageDepth();
		int getFormatImageChannels();
		int getFormatVideo();
		int getFPS();
		int getCompressionVideo();
	int getVideoFramerate();
	int getNumberFrame();
	double getCurrentFramerate();
	int getCurrentFrame();
	QString getResolution();

	QPixmap getPixmapVideo(int type);

	double get_sip_number_points();
	double get_stip_number_points();
	double get_nb_objects();
	double get_hough_lines();
	double get_hough_circles();
	double get_hough_orientation();
	//double get_hough_focalisation();
	double get_cmvt_intensity();
	double get_cmvt_orientation();
	double get_cmvt_percentage();
	double get_color_luminance();
	double get_color_dominant1();
	double get_color_dominant2();

	bool getStop();
	void initStop();

	void zeroCurrentFrame();

	videoprocessor processor;
	bool getSTIPCalculating();
	int countSequences();
	int set_Mode(bool value);
	void initBD(QString filename);
	void eraseAllBD();
	void eraseLastBD();

	void extractData();

	QString recupererInformations();

	void recupererInformationsBase();
	int getNBPlan();
	int getNBImage();
	int getNBObjet();
	int getNBBrique();
	int getNBBrik();

private:
	int indexSequence;
	// zone 1

	QImage IplToQImage(const IplImage *newImage);

	//xmlprocessor *resultat;
	//xmlprocessor *params;

    QString videoFilename;
	bool controlLoading,stop;
	CvCapture* videoCapture;
	CvCapture* previewCapture;
	IplImage *image;
	CvSize videoSize;
	double time,currentFramerate;
	int videoFramerate,numberFrame,currentFrame,currentTime;
	int number,current;
	CvVideoWriter* writer0,*writer1,*writer2,*writer3,*writer4,*writer5,*writer6,*writer7,*writer8,*writer9,*writer10,*writer11;
	LARGE_INTEGER Frequency,Before, After;
	QPixmap pix1,pix2,pix3,pix4,pix5,pix6,pix7,pix8,pix9;//,pix10,pix11,pix12;
	QPixmap preview;
	tools mytools;

	// informations globales
	double fo_average_intensity,fo_average_orientation,sip_number_points,stip_number_points;
	double hough_lines,hough_circles,hough_orientation;//,hough_focalisation;
	double color_luminance,color_dominant1,color_dominant2;
	double cmvt_intensity,cmvt_orientation,cmvt_percentage;
	// informations par objet
	int objetNumber;
	std::vector<double> sip_number,stip_number,fo_intensity,fo_orientation,objet_size,objet_compacity;


	int nbplan,nbimage,nbobjet,nbbriques,nbbriquesreelles;

	// zone 2
	int currentAnswer;


	int fps;
	int channels;
	int depth;
	int formatImage;
	int formatVideo;
	int compressionVideo;

	QString frameNameAvecIndice(int indice);

bool mode;
	sqlprocessor *bdsequence;


};
#endif /* CONTROLER_H_ */
